import java.util.Scanner;

class ListNode{
    int val;
    ListNode next;

    public ListNode(int val) {
        this.val = val;
    }
}

public class PalindromeList {
    public boolean chkPalindrome(ListNode A){
        //1、找到链表的中间节点
        ListNode fast = A;
        ListNode slow = A;
        while(fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
        }
        //2、反转链表
        ListNode cur = slow.next;
        while(cur != null){
            ListNode curN = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curN;
        }
        //3、引用A与slow同时移动
        while(A != slow){
            if(A.val != slow.val){
                return false;
            }
            //判断偶数个节点情况
            if(A.next == slow){
                return true;
            }
            A = A.next;
            slow = slow.next;
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int len = in.nextInt();
            ListNode dummy = new ListNode(0); // 创建虚拟头节点
            ListNode tail = dummy;
            for(int i = 0; i < len; i++){
                int val = in.nextInt(); // 读取节点值
                tail.next = new ListNode(val);
                tail = tail.next;
            }
            PalindromeList palindromeList = new PalindromeList();
            boolean result = palindromeList.chkPalindrome(dummy.next);
            System.out.println(result);
        }
    }
}
